package com.xy.cloud.config;

import com.xy.cloud.domain.dto.UserAddMoneyDTO;
import com.xy.cloud.service.UserAccountService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "add-amount",consumerGroup = "cloud-group",messageModel = MessageModel.BROADCASTING)
public class AddUserAmountListener implements RocketMQListener<UserAddMoneyDTO> {

    private static final Logger log = LoggerFactory.getLogger(AddUserAmountListener.class);

    @Autowired
    private UserAccountService userAccountService;

    /**
     * 收到消息的业务逻辑
     */
    @Override
    public void onMessage(UserAddMoneyDTO userAddMoneyDTO) {
        log.info("=====================received message: {}",userAddMoneyDTO);
        userAccountService.increaseAmount(userAddMoneyDTO);
        log.info("=====================add money success");
    }
}